<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>推送模板编辑</h2>
    </div>
    <div class="tab-wrap">
        <div class="tab-content">
            <form id="form" action="{:U('')}" method="post" class="form-horizontal"  enctype="multipart/form-data">
                <input type="hidden" name='id' value='{$data.id}'/>
                <div id="tab1" class="tab-pane tab1 in">
                    <!--TAB S-->
                    <div class="form-item cf">
                        <label class="item-label">模板标题<span class="check-tips">（输入模板的标题）</span></label>
                        <div class="controls">
                            <input type="text" class="text input-large" name="title" value="{$data.title}">
                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">模板简码<span class="check-tips">（输入模板的简码）</span></label>
                        <div class="controls">
                            <input type="text" class="text input-large" name="bin" value="{$data.bin}">
                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">公众号模板ID<span class="check-tips">（输入公众号模板的模板ID）</span></label>
                        <div class="controls">
                            <input type="text" class="text input-large" name="templet" value="{$data.templet}">
                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">模板跳转url<span class="check-tips">（输入模板跳转url）</span></label>
                        <div class="controls">
                            <input type="text" class="text input-large" name="jump_url" value="{$data.jump_url}">
                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">模板参数<span class="check-tips"><a href='#' class='btn btn-primary' id="addspec">添加新参数</a></span></label>
                        <div class="controls">
                            <div style="border: #000 1px solid;width:100%" class='data-table table-striped'>
                                <table  style="width: 100%">
                                    <thead>
                                    <tr>
                                        <th style="width:15%">key</th>
                                        <th style="width:15%">value</th>
                                        <th style="width:15%">颜色编号</th>
                                        <th style="width:15%">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody id="tbodyspec">
                                    <volist name="data.paramlist" id="vo">
                                        <tr id="spec_{$vo.id}">

                                            <td style="width:10%"><input type="text" class="text input-small" style="width:160px;" value="{$vo.pkeys}" placeholder="key" ></td>
                                            <td style="width:10%"><input type="text" class="text input-small" style="width:320px;" value="{$vo.pvalues}" placeholder="value" ></td>
                                            <td style="width:10%"><input type="text" class="text input-small" style="width:100px;" value="{$vo.pcolors}" placeholder="颜色编号" ></td>
                                            <td style="width:10%">
                                                <a href='#' class='btn btn-primary paramdelajax' data-id="{$vo.id}">删除</a>
                                            </td>
                                        </tr>
                                    </volist>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">模板详情<span class="check-tips">（输入模板详情）</span></label>
                        <div class="controls">
                            {:hook('adminArticleEdit', array('name'=>'content'))}
                            <textarea name="content">{$data.content}</textarea>
                        </div>
                    </div>
                    <!--tab e-->
                </div>
                <div class="form-item cf">
                    <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal" autocomplete="off">确认保存</button>
                    <button class="btn btn-return" onclick="javascript:history.back(-1); return false;">返 回</button>
                </div>
            </form>
        </div>
    </div>
</block>

<block name="script">
    <script type="text/javascript">
        $(document).ready(function () {
            $('#addspec').click(function () {
                var html = '<tr><td style="width:10%"><input type="text" class="text input-small" style="width:160px;" name="newpkeys[]" value="" placeholder="key" ></td><td style="width:10%"><input type="text" class="text input-small" style="width:160px;" name="newpvalues[]" value="" placeholder="value" ></td><td style="width:10%"><input type="text" class="text input-small" style="width:160px;" name="newpcolors[]" value="" placeholder="颜色编号" ></td><td style="width:6%"><a href="#" class="btn btn-primary trdelspec">删除</a></td></tr>';
                $('#tbodyspec').append(html);

                $('.trdelspec').bind("click", function(){
                    $(this).parent().parent().remove();
                });
            });

            $('.paramdelajax').click(function () {
                if(window.confirm("请仔细核确认，需要删除此模板参数吗？")){
                    var id = $(this).data('id');
                    var THIS= $(this).parent().parent();
                    $.post("{:U('Pushed/paramdelajax')}", {id: id},
                            function (data) {
                                alert(data.info);
                                THIS.remove();
                            }, "json");
                }
            });
        });

        highlight_subnav('{:U('Pushed/index')}');
    </script>
</block>